package guoanmaker.operator.business.repository;

import guoanmaker.operator.business.model.OperatorServerClass;


import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 
* @ClassName: OperatorServerClassRepository
* @Description:TODO (这里用一句话描述这个类的作用) 
* @author lihongyu
* @date 2017年8月23日 下午4:15:03 
*  
 */
public interface OperatorServerClassRepository extends JpaRepository<OperatorServerClass, String>, JpaSpecificationExecutor<OperatorServerClass> {
    //	@Query("select u from OperatorUser u left join fetch u.roles r where u.username=:username")
//    public Optional<OperatorUser> findByUsername(@Param("username") String username);
    Integer countAllByIdIsNotNull();
    @Query("select u from OperatorServerClass u  where u.parentServerId=:parentServerId  and u.deleteState=0 order by u.serWeight ASC")
    ArrayList<OperatorServerClass> findByParentServerId(@Param("parentServerId") String parentServerId);
    
    @Query("select t from  OperatorServerClass t where t.parentServerId = :parentServerId and t.deleteState=0 order by t.serWeight ASC")
    ArrayList<OperatorServerClass> findAllByParentServerId(@Param("parentServerId") String parentServerId);
    
    List<OperatorServerClass> findByIdIn(Collection<String> ids);
    
    @Query("select t from  OperatorServerClass t  where t.serverLevel = 1 and t.deleteState=0")
    List<OperatorServerClass>   selectByOneServerclass();
    @Query("select t from  OperatorServerClass t  where t.serverLevel = 2 and t.deleteState=0")
    List<OperatorServerClass>   selectByTwoServerclass();
    @Query("select t from  OperatorServerClass t  where t.serverLevel = 3 and t.deleteState=0")
    List<OperatorServerClass>   selectByThreeServerclass();
    List<OperatorServerClass> findByIdInAndServerTypeIs(Collection<String> parentServerIds,Integer serverType);
    
    @Query("select u from OperatorServerClass u  where u.serverLevel=1 and u.deleteState=0 order by u.serWeight ASC")
    public List<OperatorServerClass> findListBylevel();
    
    @Query("select u from OperatorServerClass u  where u.serverLevel=1  and u.pcNavigation=:pcNavigation and u.deleteState=0 order by u.serWeight ASC")
    public List<OperatorServerClass> findListBypcNavigation(@Param("pcNavigation") String pcNavigation);
}